﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <link href="~/css/framework-font.css" rel="stylesheet" />
    <link href="~/css/framework-theme.css" rel="stylesheet" />
    <script src="~/lib/jquery/1.12.4/jquery.min.js"></script>
    <script src="~/lib/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="~/lib/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/lib/wdtree/tree.js"></script>
    <link href="~/lib/wdtree/tree.css" rel="stylesheet" />
    <link href="~/lib/select2/select2.min.css" rel="stylesheet" />
    <script src="~/lib/select2/select2.min.js"></script>
    <script src="~/lib/laydate/laydate.js"></script>
    <script src="~/lib/moment/moment.js"></script>
    <link href="~/lib/wizard/wizard.css" rel="stylesheet" />
    <script src="~/lib/wizard/wizard.js"></script>
    <script src="~/lib/validate/jquery.validate.min.js"></script>
    <script src="~/lib/datepicker/WdatePicker.js"></script>
    <script src="~/lib/jqgrid/5.3.0/i18n/grid.locale-cn.js"></script>
    <link href="~/css/framework-ui.css" rel="stylesheet" />
    <script src="~/js/framework-ui.js"></script>
</head>
<body>
    <form id="form1">
        <div style="padding-top: 20px; margin-right: 20px;">
            <table class="form">
                <tr>
                    <th class="formTitle">租户账号</th>
                    <td class="formValue">
                        <input id="TenantName" name="TenantName" type="text" class="form-control required" placeholder="请输入微信号" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">租户名称</th>
                    <td class="formValue">
                        <input id="FullName" name="FullName" type="text" class="form-control required" placeholder="请输入公众号名称" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">允许登录</th>
                    <td class="formValue">
                        <select id="EnabledMark" name="EnabledMark" class="form-control required">
                            <option value="true">是</option>
                            <option value="false">否</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        备注
                    </th>
                    <td class="formValue">
                        <textarea id="Description" name="Description" class="form-control" style="height: 100px;"></textarea>
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <script>
        var keyValue = $.request("keyValue");
        $(function () {
            initControl();
            if (!!keyValue) {
                $.ajax({
                    url: "/SystemManage/Tenant/GetFormJson",
                    data: { keyValue: keyValue },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        $("#TenantName").attr('disabled', 'disabled');
                        $("#form1").formSerialize(data);
                    }
                });
            }
        });
        function initControl() {
            $("#EnabledMark").bindSelect();
        }
        function submitForm() {
            if (!$('#form1').formValid() || !validTenantNameFormat()) {
                return false;
            }            
            $.submitForm({
                url: "/SystemManage/Tenant/SubmitForm?keyValue=" + keyValue,
                param: $("#form1").formSerialize(),
                success: function () {
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            })
        }
        function validTenantNameFormat() {
            var tenantname = $("#TenantName").val();
            if (tenantname == "" || tenantname == null) {
                $.modalMsg("租户名不能为空，请填写租户名。", "error");
                return false;
            }
            else if (/^\d.*$/.test(tenantname)) {
                $.modalMsg("您输入的租户名“" + tenantname + "”格式不正确，租户名不能以数字开头。", "error");
                return false;
            }
            else if (! /^.{6,20}$/.test(tenantname)) {
                $.modalMsg("您输入的租户名“" + tenantname + "”字符长度有误，合法长度为6-20个字符。", "error");
                return false;
            }
            else if (! /^[\w_]*$/.test(tenantname)) {
                $.modalMsg("您输入的租户名“" + tenantname + "”含有非法字符，用户名只能包含_,英文字母，数字。", "error");
                return false;
            }
            else if (! /^([a-z]|[A-Z])[\w_]{5,19}$/.test(tenantname)) {
                $.modalMsg("您输入的租户名“" + tenantname + "”格式不正确，用户名只能包含_,英文字母，数字。", "error");
                return false;
            }
            else {
                return true;
            }
        }
    </script>
</body>
</html>
